#include "Common.h"
#include "InputBoxFPS.h"
#include "LocalPlayer.h"
#include <windows.h>

InputBoxFPS::InputBoxFPS(LocalPlayer* player)
	: mLocalPlayer(player)
	, mMoveVector(0)
	, mRotateSpeed(50.0f)
{
}

InputBoxFPS::~InputBoxFPS()
{
}

void InputBoxFPS::Update(float elapsedTime)
{
	mPosition = mLocalPlayer->getCameraPos();
	mRotation = mLocalPlayer->getRotation();
}

bool InputBoxFPS::OnMouseMove(long deltaX, long deltaY)
{
	float rotateX = -deltaX * mRotateSpeed * 0.5f;
	float rotateY = -deltaY * mRotateSpeed;
	mLocalPlayer->Rotate(rotateX, rotateY);
	return true;
}


bool InputBoxFPS::OnKeyDown(int key)
{
	switch (key)
	{
	case 'W':		mMoveVector.Z = 1;		break;
	case 'A':		mMoveVector.X = -1;		break;
	case 'S':		mMoveVector.Z = -1;		break;
	case 'D':		mMoveVector.X = 1;		break;
	case VK_SPACE:	mLocalPlayer->Jump();	return true;
	default:
		return false;
	}

	mLocalPlayer->SetMoveDir(mMoveVector);
	return true;
}

bool InputBoxFPS::OnKeyUp(int key)
{
	switch (key)
	{
	case 'W':		mMoveVector.Z = 0;		break;
	case 'A':		mMoveVector.X = 0;		break;
	case 'S':		mMoveVector.Z = 0;		break;
	case 'D':		mMoveVector.X = 0;		break;
	default:
		return false;
	}

	mLocalPlayer->SetMoveDir(mMoveVector);
	return true;
}

bool InputBoxFPS::MsgProc(void* hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	switch (msg)
	{
	case WM_KEYDOWN:
		OnKeyDown(wParam);
		break;
	case WM_KEYUP:
		OnKeyUp(wParam);
		break;
	default:
		return false;
	}
	return true;
}

